package baiwa.rta.dao.mapping;

import baiwa.rta.model.RMcdhdrModel;
import baiwa.rta.model.TowerModel;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;


public class ConciergeDepositHeaderMapping implements RowMapper<RMcdhdrModel> {

    public RMcdhdrModel mapRow(ResultSet rs, int line) throws SQLException {
        ResultSetExtractor<RMcdhdrModel> extractor = new ResultSetExtractor<RMcdhdrModel>() {
            public RMcdhdrModel extractData(ResultSet rs) throws SQLException, DataAccessException {
                RMcdhdrModel model = new RMcdhdrModel();
                model.setCdhid(rs.getInt("CDHID"));
                model.setCdhdocno(rs.getString("CDHDOCNO"));
                model.setRlrmid(rs.getInt("RLRMID"));
                model.setCdhdocstatus(rs.getString("CDHDOCSTATUS"));
                model.setCdhrcvdat(rs.getDate("CDHRCVDAT"));
                model.setCdhreqto(rs.getString("CDHREQTO"));
                model.setCdhreqby(rs.getString("CDHREQBY"));
                model.setCdhreqtel(rs.getString("CDHREQTEL"));
                model.setCdhreqemail(rs.getString("CDHREQEMAIL"));
                model.setCdhdephoby(rs.getString("CDHDEPHOBY"));
                model.setCdhdephodat(rs.getDate("CDHDEPHODAT"));
                model.setCdhdeprcvby(rs.getString("CDHDEPRCVBY"));
                model.setCdhdeprcvdat(rs.getDate("CDHDEPRCVDAT"));
                model.setCdhrcvrcvby(rs.getString("CDHRCVRCVBY"));
                model.setCdhrcvrcvdat(rs.getDate("CDHRCVRCVDAT"));
                model.setCdhrcvhoby(rs.getString("CDHRCVHOBY"));
                model.setCdhrcvhodat(rs.getDate("CDHRCVHODAT"));
                model.setCdhcreby(rs.getString("CDHCREBY"));
                model.setCdhcredat(rs.getDate("CDHCREDAT"));
                model.setCdhupdby(rs.getString("CDHUPDBY"));
                model.setCdhupddat(rs.getDate("CDHUPDDAT"));

              /* ---- Tower Data From Join Table------*/
                TowerModel tower = new TowerModel();
                tower.setTower(rs.getString("RLSTTOWER"));
                tower.setFloor(rs.getString("RLSTFLOOR"));
                tower.setUnitNo(rs.getString("RLSTUNITNO"));
                tower.setAddress(rs.getString("RLSTADDR"));
                model.setTower(tower);
                
                return model;
            }
        };
        return extractor.extractData(rs);
    }
}
